package org.spiderflow.core.expression.parsing.enums;

import org.spiderflow.core.expression.ExpressionError;
import org.spiderflow.core.expression.parsing.token.Token;
import org.spiderflow.core.expression.parsing.token.TokenType;

/**
 * 一元表达式
 *
 * @author zhaoshihao
 * @version 2021/11/9 15:13
 */
public enum UnaryOperator {
    /**
     * 不等于
     */
    NOT,
    /**
     * 加号
     */
    NEGATE,
    /**
     * 减号
     */
    POSITIVE;

    public static UnaryOperator getOperator(Token op) {
        if (op.getType() == TokenType.NOT) {
            return NOT;
        }
        if (op.getType() == TokenType.PLUS) {
            return POSITIVE;
        }
        if (op.getType() == TokenType.MINUS) {
            return NEGATE;
        }
        ExpressionError.error("Unknown unary operator " + op + ".", op.getSpan());
        // not reached
        return null;
    }
}